import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { PetEggRankModule } from "../../../modules/PetEggRankModule";
import { DataEvent } from "../events/DataEvent";
import { GameConst } from "../../component/gconst/GameConst";
import { GameProxy } from "../mvc/GameProxy";
import { IPetEggRandModule } from "../../../modules/interfaces/IPetEggRandModule";
type int = number;
//class PetEggRandController
    
    export  class PetEggRandController extends Controller
    {
        constructor()
        {
            
            super();Dispatcher.addEventListener(EventName.PetEggRandOpen, this.onPetEggRandOpenHandler);
            Dispatcher.addEventListener(EventName.PetEggRandUse, this.onPetEggRandUseHandler);
            Dispatcher.addEventListener(EventName.PetEggRandUseSuccess, this.onPetEggRandUseSuccessHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._petEggRandModule) 
            {
                this._petEggRandModule = new PetEggRankModule();
            }
            return this._petEggRandModule;
        }

        /* internal  */onPetEggRandOpenHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            this.initView();
            this._petEggRandModule.updateModule(loc1, GameConst.PetEggRandomGiftBag);
            this._petEggRandModule.show();
            return;
        }

        /* internal  */onPetEggRandUseHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["uid"] as string;
            var loc2=arg1.data["itemCode"] as int;
            GameProxy.packProxy.useRandPetEgg(loc1, loc2);
            return;
        }

        /* internal  */onPetEggRandUseSuccessHandler(arg1: DataEvent): void
        {
            if (this._petEggRandModule && this._petEggRandModule.isHide == false) 
            {
                this._petEggRandModule.hide();
            }
            return;
        }

        private /* var */_petEggRandModule: IPetEggRandModule;
    }
